package com.tianqi.modules.tqs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tianqi.modules.tqs.mapper.TimeConvertInfoMapper;
import com.tianqi.modules.tqs.model.TimeConvertInfoData;
import com.tianqi.modules.tqs.service.TimeConvertInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @className: TimeConvertInfoServiceImpl
 * @description: 真太阳时时差表实现类
 * @author: zp
 * @create: 2023-08-08 21:06
 **/
@Slf4j
@Service("TimeConvertInfoService")
public class TimeConvertInfoServiceImpl implements TimeConvertInfoService {
    @Autowired
    private TimeConvertInfoMapper timeConvertInfoMapper;
    @Override
    public String timeConvertInfoSave(TimeConvertInfoData data) {
        QueryWrapper<TimeConvertInfoData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("addr", data.getAddr());
        TimeConvertInfoData infoData = timeConvertInfoMapper.selectOne(queryWrapper);
        if(infoData==null){
            timeConvertInfoMapper.insert(data);
        }else{
            data.setId(infoData.getId());
            timeConvertInfoMapper.updateById(data);
        }
        return "成功";
    }

    @Override
    public TimeConvertInfoData timeConvertInfoQueryOne(TimeConvertInfoData data) {
        QueryWrapper<TimeConvertInfoData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("addr", data.getAddr());
        TimeConvertInfoData infoData = timeConvertInfoMapper.selectOne(queryWrapper);
        if(infoData!=null){
            return infoData;
        }else{
            return new TimeConvertInfoData();
        }
    }
}
